<template>
  <div>
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
      <!-- <el-form-item label="用户编号" prop="uId">
        <el-input v-model="ruleForm.uId" placeholder="请输入编号信息" style="width: 260px"></el-input>
      </el-form-item> -->
      <el-form-item label="用户姓名" prop="username">
        <el-input v-model="ruleForm.username" placeholder="请输入用户名称" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="用户密码" prop="password">
        <el-input v-model="ruleForm.password" value="123456" placeholder="请输入用户密码" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="用户类型" prop="uType">
        <el-select v-model="ruleForm.uType" placeholder="请选择" style="width: 260px">
          <el-option label="超级管理员" value="1"></el-option>
          <el-option label="客服" value="2"></el-option>
          <el-option label="任务调度" value="3"></el-option>
          <el-option label="技术工程师" value="4"></el-option>
          <el-option label="库管" value="5"></el-option>
          <el-option label="运营监督" value="6"></el-option>
        </el-select>
      </el-form-item>

     <el-form-item style="margin-top: 20px">
        <el-button type="primary" @click="addUser('ruleForm')">提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
    
  </div>
</template>
<script>
import {addUser as addUser} from '../../../api/user';

export default {
  props:["uId"],
  data() {
    return {
      ruleForm: {
        uId: "",
        username: "",
        password: "123456",
        uType: "",
        isEffectice:"1"
      },
      rules: {

        username: [
          { required: true, message: "请输入客户姓名", trigger: "blur" },
          { min: 1, max: 10, message: "长度在 1-10个字符", trigger: "blur" }
        ],
        uId: [
          { required: true, message: "请输入编号", trigger: "blur" }
        ],
        uType: [
          { required: true, message: "请选择用户类型", trigger: "blur" }
        ],
        
        password: [
          { required: true, message: "请输入密码", trigger: "blur" }
        ],
      },
       buttonText:"修改"
      //buttonText:"创建"
    }
  },
  created(){
           
    },
  components: {},
  methods: {
    addUser(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
            // 设置提交的参数
            let param = new URLSearchParams();
            param.append('uId',this.ruleForm.uId);
            param.append("username", this.ruleForm.username);
            param.append("password", this.ruleForm.password);
            param.append("uType", this.ruleForm.uType);
            param.append("isEffectice",this.ruleForm.isEffectice);
            if(this.ruleForm.username == ""){
            alert("请输入用户名称！");
            }else if(this.ruleForm.password == ""){
            alert("请输入密码！");
            }else if(this.ruleForm.uType == ""){
            alert("请输入用户类型！");
            }else{
            let that = this;
            addUser(param).then(r=>{
                setTimeout(() => {
                this.$notify({
                    title:"新增用户成功",
                    type:"success"
                });
                },1000);
                this.$layer.closeAll(); //疯狂模式，关闭所有层
                location.reload(true) //关闭刷新
            }).catch(_=>{
              this.$notify({
                    title:"新增用户失败",
                    type:"false"
                });
                console.log(r);
            });
          }

        } else {
          console.log("新增失败");
          return false;
        }
      });
    },
    resetForm(formName){
        this.$refs[formName].resetFields();
    },
    
  }
};
</script>